package com.ldwx.center.service.impl;


import com.ldwx.center.dao.CompanyDao;
import com.ldwx.center.model.Company;
import com.ldwx.center.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;


/**
 * 公司模块service
 */
@Service
public class CompanyServiceImpl implements CompanyService{
    @Autowired
    private CompanyDao companyDao;

    @Override
    public void addCompany(Company company) {
        companyDao.save(company);
    }

    @Override
    public Company findCompanyByName(String name) {
        Company company = new Company();
        company.setCompanyName(name);
        Example<Company> example = Example.of(company);
        Optional<Company> optional = companyDao.findOne(example);
        Company result = null;
        if(optional.isPresent()){
            result = optional.get();
        }
        return result;
    }
}
